from flask import Flask, jsonify
import argparse

app = Flask(__name__)

INNER_PORT = None

def hello_world(port):
    print(f"Hello World, port = {port}")
    return f"Hello World from port {port}"

@app.route("/get_data")
def get_data():
    message = hello_world(INNER_PORT)
    return jsonify({"message": message, "inner_port": INNER_PORT})

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--port", type=int, required=True, help="外部端口")
    args = parser.parse_args()

    port_mapping = {5003: 5007, 5004: 5008}
    INNER_PORT = port_mapping.get(args.port)

    print(f"启动 Flask 服务，外部端口 {args.port} -> 内部端口 {INNER_PORT}")

    app.run(host="0.0.0.0", port=args.port)
